package com.visizen.wisdomclass.server.client;

import com.visizen.wisdomclass.server.model.WcClassSyllabus;
import com.visizen.wisdomclass.server.model.WcClassSyllabusExample;
import com.visizen.wisdomclass.server.model.WcCourse;
import com.visizen.wisdomclass.server.model.WcUser;
import com.visizen.wisdomclass.server.model.dto.ClassSyllabusExt;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface WcClassSyllabusMapper {
    @Select(" SELECT\n" +
            "  wcs.*,\n" +
            "  c.course_name courseName,u.user_id teacherId\n" +
            " FROM wc_class_syllabus wcs, wc_course c,wc_user u, wc_teacher_course tc\n" +
            " WHERE syllabus_id IN (\n" +
            "  SELECT\n" +
            "    syllabus_id\n" +
            "  FROM wc_class_syllabus\n" +
            "  WHERE organization_id = #{classId} AND term_id = #{termId})\n" +
            "      AND c.course_id = wcs.course_id\n" +
            "  and u.user_id = tc.user_id and tc.organization_id=wcs.organization_id and tc.course_id=wcs.course_id\n" +
            " ORDER BY WEEK;")
    @Results({
            @Result(property = "courseName", column = "courseName"),
            @Result(property = "teacherId", column = "teacherId")
    })
    List<ClassSyllabusExt> selectByClassIdAndTermId(@Param("classId") Long classId,
                                                    @Param("termId") Long termId);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_class_syllabus
     *
     * @mbggenerated
     */
    @SelectProvider(type = WcClassSyllabusSqlProvider.class, method = "countByExample")
    int countByExample(WcClassSyllabusExample example);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_class_syllabus
     *
     * @mbggenerated
     */
    @DeleteProvider(type = WcClassSyllabusSqlProvider.class, method = "deleteByExample")
    int deleteByExample(WcClassSyllabusExample example);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_class_syllabus
     *
     * @mbggenerated
     */
    @Delete({"delete from wc_class_syllabus",
            "where syllabus_id = #{syllabus_id,jdbcType=BIGINT}"})
    int deleteByPrimaryKey(Long syllabus_id);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_class_syllabus
     *
     * @mbggenerated
     */
    @Insert({
            "insert into wc_class_syllabus (syllabus_id, organization_id, ",
            "term_id, course_id, ",
            "WEEK, rank)",
            "values (#{syllabus_id,jdbcType=BIGINT}, #{organization_id,jdbcType=BIGINT}, ",
            "#{term_id,jdbcType=BIGINT}, #{course_id,jdbcType=BIGINT}, ",
            "#{WEEK,jdbcType=INTEGER}, #{rank,jdbcType=INTEGER})"})
    int insert(WcClassSyllabus record);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_class_syllabus
     *
     * @mbggenerated
     */
    @InsertProvider(type = WcClassSyllabusSqlProvider.class, method = "insertSelective")
    int insertSelective(WcClassSyllabus record);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_class_syllabus
     *
     * @mbggenerated
     */
    @SelectProvider(type = WcClassSyllabusSqlProvider.class, method = "selectByExample")
    @Results({
            @Result(column = "syllabus_id", property = "syllabus_id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "organization_id", property = "organization_id", jdbcType = JdbcType.BIGINT),
            @Result(column = "term_id", property = "term_id", jdbcType = JdbcType.BIGINT),
            @Result(column = "course_id", property = "course_id", jdbcType = JdbcType.BIGINT),
            @Result(column = "WEEK", property = "WEEK", jdbcType = JdbcType.INTEGER),
            @Result(column = "rank", property = "rank", jdbcType = JdbcType.INTEGER)})
    List<WcClassSyllabus> selectByExample(WcClassSyllabusExample example);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_class_syllabus
     *
     * @mbggenerated
     */
    @Select({"select",
            "syllabus_id, organization_id, term_id, course_id, WEEK, rank",
            "from wc_class_syllabus",
            "where syllabus_id = #{syllabus_id,jdbcType=BIGINT}"})
    @Results({
            @Result(column = "syllabus_id", property = "syllabus_id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "organization_id", property = "organization_id", jdbcType = JdbcType.BIGINT),
            @Result(column = "term_id", property = "term_id", jdbcType = JdbcType.BIGINT),
            @Result(column = "course_id", property = "course_id", jdbcType = JdbcType.BIGINT),
            @Result(column = "WEEK", property = "WEEK", jdbcType = JdbcType.INTEGER),
            @Result(column = "rank", property = "rank", jdbcType = JdbcType.INTEGER)})
    WcClassSyllabus selectByPrimaryKey(Long syllabus_id);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_class_syllabus
     *
     * @mbggenerated
     */
    @UpdateProvider(type = WcClassSyllabusSqlProvider.class, method = "updateByExampleSelective")
    int updateByExampleSelective(@Param("record") WcClassSyllabus record,
                                 @Param("example") WcClassSyllabusExample example);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_class_syllabus
     *
     * @mbggenerated
     */
    @UpdateProvider(type = WcClassSyllabusSqlProvider.class, method = "updateByExample")
    int updateByExample(@Param("record") WcClassSyllabus record,
                        @Param("example") WcClassSyllabusExample example);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_class_syllabus
     *
     * @mbggenerated
     */
    @UpdateProvider(type = WcClassSyllabusSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(WcClassSyllabus record);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_class_syllabus
     *
     * @mbggenerated
     */
    @Update({"update wc_class_syllabus",
            "set organization_id = #{organization_id,jdbcType=BIGINT},",
            "term_id = #{term_id,jdbcType=BIGINT},",
            "course_id = #{course_id,jdbcType=BIGINT},",
            "WEEK = #{WEEK,jdbcType=INTEGER},",
            "rank = #{rank,jdbcType=INTEGER}",
            "where syllabus_id = #{syllabus_id,jdbcType=BIGINT}"})
    int updateByPrimaryKey(WcClassSyllabus record);
}